/**
 * @file cm_mpu_ctrl.c
 * @author jmdvirus
 */

#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include "cm_mpu_ctrl.h"
#include "cm_common.h"

static int count = 0;

static CMMpuImpl *cm_mpu_impl_list[10] = {
    NULL,
};

const CMMpuImpl *cm_mpu_impl_find(const char *type)
{
    CMMpuImpl *impl = NULL;
    int          i    = 0;
    while ((impl = (CMMpuImpl *)cm_mpu_impl_list[i++]) != NULL)
    {
        if (strlen(impl->name) == strlen(type) && strcmp(impl->name, type) == 0)
        {
            return impl;
        }
    }
    return NULL;
}

int cm_mpu_register_impl(const CMMpuImpl *impl)
{
    if (count >= 10)
    {
        return -1;
    }
    cm_mpu_impl_list[count] = (CMMpuImpl*)impl;
    cm_mpu_impl_list[count+1] = NULL;
    count++;
    LOGD("register impl , remain count [%d]\n", count);
    return count;
}
